package com.dengyafei.exception;

import com.dengyafei.result.RestApiResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 邓亚非
 */
@RestControllerAdvice(annotations = RestController.class)
public class BaseControllerExceptionHandler {

    /**
     * 基于BaseException的异常捕捉
     *
     * @param e
     * @return
     */
    @ExceptionHandler({BaseException.class})
    public RestApiResult baseException(HttpServletRequest request, BaseException e) {
        return new RestApiResult(e);
    }

    /**
     * 基于Exception的异常捕捉
     *
     * @param e
     * @return
     */
    @ExceptionHandler({Exception.class})
    public RestApiResult exception(HttpServletRequest request, Exception e) {
        return new RestApiResult(e);
    }
}